﻿@{
    var AdminMenuList = ViewBag.GetAdminMenu as List<chihuopig.Model.AdminMenu>;
}
@section Header{

}
<div class="x-body">
    <form class="layui-form" id="formdiv">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>权限规则
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="username" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="">
            </div>

        </div>
        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="x-red">*</span>权限名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_pass" name="AuthorName" required="" lay-verify="pass"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="x-red">*</span>所属分类
            </label>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="MenuId" lay-verify="required">
                        @foreach (chihuopig.Model.AdminMenu item in AdminMenuList)
                        {
                            <option value="@item.Id">@item.Name </option>
                        }
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="x-red">*</span>授权代码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_repass" name="AuthorCode" required="" lay-verify="repass"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <input type="button" class="layui-btn" value="增加" id="btnSave" />
        </div>
    </form>
</div>
@section footer
    {
    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

            $("#btnSave").click(function () {
                if ($("input[name='username']").val() == "") {
                    layer.msg("权限规则不能为空", { icon: 2 });
                    return;
                }
                if ($("input[name='username']").val().length > 35) {
                    layer.msg("权限规则最大长度20", { icon: 2 });
                    return;
                }
                if ($("input[name='AuthorName']").val() == "") {
                    layer.msg("权限名称不能为空", { icon: 2 });
                    return;
                }
                if ($("input[name='AuthorName']").val().length > 20) {
                    layer.msg("权限名称最大长度20", { icon: 2 });
                    return;
                }
                if ($("input[name='AuthorCode']").val() == "") {
                    layer.msg("授权代码不能为空", { icon: 2 });
                    return;
                }
                if ($("input[name='AuthorCode']").val().length > 20) {
                    layer.msg("授权代码最大长度20", { icon: 2 });
                    return;
                }
                var formdiv = $("#formdiv").serializeArray();
                formdiv.push({ "name": "adminruleId", "value": "1" });
           /* */$.post("/admin/adminrule/adminruleAdd",
                 formdiv, function (data) {

                if (!data.succeed) {

                    layer.msg(data.msg);

                }
                else
                {
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                }
             })
        });
    });
    </script>
}


